import {
  curTime1
} from '../../third-utils/time/index.js';
Page({

    /**
     * 页面的初始数据
     */
    data: {
      curId:'',
      measureDate:'',
      babyInfo:{
        birthday:'2023-07-01'
      },
      babyId:'',
      height:'',
      weight:'',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(e) {

        
      this.setData({
        babyId:e.babyId,
        measureDate:curTime1
      })
      if(e.id){
        this.setData({
          curId:e.id
        })
          // this.initData(e.id)
      }
    },
    initData(curId){
      
    wx.request({
      url: 'https://babyplanet.isv-dev.youzan.com/api/babyBMI/view',
      data:{
        id:curId
      },
      method: 'get',
      success:  (res)=> {
        console.log(res,122)
        if (res.data.code == 200) {
          let info=res.data.data
          this.setData({
            measureDate:info.measureDate,
            height:info.height,
            weight:info.weight,
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000 //持续的时间
          })
        }
      }
    })
    },
    
  formSubmit(e){
    console.log(e,12122)
    let url='https://babyplanet.isv-dev.youzan.com/api/babyBMI/add'
      let post={
        babyId:this.data.babyId,
        measureDate:this.data.measureDate,
        height:e.detail.value.height,
        weight:e.detail.value.weight,
      }
      if(this.data.curId){
        post.id=this.data.curId
        url='https://babyplanet.isv-dev.youzan.com/api/babyBMI/update'
      }
    wx.request({
      url: url,
      data:post,
      method: 'post',
      success:  (res)=> {
        console.log(res,122)
        if (res.data.code == 200) {
          
          wx.showToast({
            title: '保存成功！',
            icon: 'none',
            duration: 1500 //持续的时间
          })
          setTimeout(()=>{
            wx.navigateBack()
          },1500)
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000 //持续的时间
          })
        }
      }
    })
  },
  bindDateChange(e){
    console.log(e,1212)
      this.setData({
        measureDate:e.detail.value
      })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})